<script setup lang="ts">
import { ref } from 'vue'
const foods = ref(['隆江猪脚饭', '白切鸡', '把子肉', '黄焖鸡'])
const alertFood = (food: string) => {
    alert(food)
}

const addFood = () => {
    foods.value.push('西兰花炒蛋')
}
</script>

<template>
    <button @click="addFood">添加食物</button>
    <div v-for="(item, index) in foods" :key="index">
        <!-- item index 来获取 值和下标 -->
        <span>{{ index + 1 }} -- {{ item }}</span>---- <button @click="alertFood(item)">购买</button>
    </div>
</template>

<style></style>